package com.github.shiqiyue.app.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.github.shiqiyue.app.modules.sys.entity.UserPermission;
import com.github.shiqiyue.app.modules.sys.mapper.UserPermissionMapper;
import com.github.shiqiyue.app.modules.sys.service.IUserPermissionService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户-权限 服务实现类
 * </p>
 *
 * @author wenyao.wu
 * @since 2018-10-17
 */
@Service
public class UserPermissionServiceImpl extends ServiceImpl<UserPermissionMapper, UserPermission> implements IUserPermissionService {


    @Override
    public List<UserPermission> findByUserId(Long userId) {
        return baseMapper.findByUserId(userId);
    }

    @Override
    public boolean deleteByUserId(Long userId) {
        return this.remove(new UpdateWrapper<UserPermission>().eq(UserPermission.USER_ID, userId));
    }

    @Override
    public boolean updateByUserId(Long userId, List<UserPermission> userPermissionList) {
        deleteByUserId(userId);
        if (CollectionUtils.isNotEmpty(userPermissionList)) {
            saveBatch(userPermissionList);
        }
        return true;
    }
}
